import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { PetCpnInfo } from "./info/PetCpnInfo";
import { EPetArenaChallenge } from "../../../../../Message/Game/EPetArenaChallenge";
import { Language } from "../../../../../extend/language/Language";
import { PetUtil } from "../info/PetUtil";
import { PetColor } from "../info/PetColor";
import { PetCpnRewardUtil } from "./info/PetCpnRewardUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BlankTipItem } from "../../common/tooltip/BlankTipItem";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { PlayerUtil } from "../../common/util/PlayerUtil";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { SPetArenaInfo } from "../../../../../Message/Game/SPetArenaInfo";
import { SReward } from "../../../../../Message/Public/SReward";
import { _petArenaInfo } from "../../../../../this/_petArenaInfo";
import { _attackType } from "../../../../../this/_attackType";
type int = number;
//class PetCpnArrangeCellRenderer
    
    export  class PetCpnArrangeCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOver);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._petCpnInfo = arg1 as PetCpnInfo;
            if (this._petCpnInfo) 
            {
                this._petArenaInfo = this._petCpnInfo.petArenaInfo;
                this._attackType = this._petCpnInfo.challengeType;
                if (this._petArenaInfo) 
                {
                    if (this._attackType != EPetArenaChallenge._EPetArenaChallengeRandom) 
                    {
                        this._rankTxt.text = this._petArenaInfo.rank.toString();
                        this._attackBtn.visible = true;
                    }
                    else 
                    {
                        this._rankTxt.text = "*";
                        if (this._petArenaInfo.challengeWin) 
                        {
                            this._attackBtn.visible = false;
                            this._resultTxt.visible = true;
                            this._resultTxt.text = Language.getString(54655);
                        }
                        else 
                        {
                            this._attackBtn.visible = true;
                            this._resultTxt.visible = false;
                        }
                    }
                    this._nameTxt.htmlText = "<a href=\'event: 0\'><u>" + this._petArenaInfo.petName + "</u></a>";
                    this._nameTxt.toolTipData = this.getTipData();
                    this._growthTxt.htmlText = PetUtil.getColorGrowth(this._petArenaInfo.growth);
                    this._spiritTxt.htmlText = PetUtil.getColorSpirit(this._petArenaInfo.spirit);
                    this._talentTxt.htmlText = PetColor.getColorTalent(this._petArenaInfo.talent);
                    this._levelTxt.text = Language.getStringByParam(28023, this._petArenaInfo.reinLevel, this._petArenaInfo.level);
                    this._typeTxt.htmlText = PetUtil.getPetTypeNameByCareer(this._petArenaInfo.career, false).substr(0, 1);
                    this._reward = this._petArenaInfo.rewards[0];
                    this._rewardTxt.htmlText = PetCpnRewardUtil.getStrByReward(this._reward);
                    this._isSystem = this._petArenaInfo.entityId.typeEx == 0;
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=10;
            graphics.beginFill(16777215, 0);
            graphics.drawRect(0, 5, 460, 30);
            graphics.endFill();
            ObjCreate.createBg(0, 8, 65, 20, this, ImagesConst.SelectedSmallBg);
            this._rankTxt = ObjCreate.createTextField("", 0, loc1, 65, 20, this, GlobalStyle.textFormat2);
            this._rankTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameTxt = ObjCreate.createGTextField("", 60, loc1, 85, 20, this, GlobalStyle.textFormat2);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameTxt.toolTipData = "";
            this._nameTxt.addEventListener(flash.events.TextEvent.LINK, this.onNameClickHandler);
            this._growthTxt = ObjCreate.createTextField("", 155, loc1, 25, 20, this);
            this._growthTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._spiritTxt = ObjCreate.createTextField("", 197, loc1, 25, 20, this);
            this._spiritTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._talentTxt = ObjCreate.createTextField("", 238, loc1, 25, 20, this);
            this._talentTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._levelTxt = ObjCreate.createTextField("", 280, loc1, 25, 20, this);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._typeTxt = ObjCreate.createTextField("", 320, loc1, 25, 20, this, GlobalStyle.textFormat6);
            this._typeTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._rewardTxt = ObjCreate.createGTextField("", 360, loc1, 100, 20, this, GlobalStyle.textFormat6);
            this._rewardTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._rewardTxt.mouseEnabled = false;
            this._rewardTipItem = new BlankTipItem(100, 35);
            this._rewardTipItem.x = 360;
            this._rewardTipItem.y = loc1;
            this._rewardTipItem.toolTipData = Language.getString(54670);
            this.addChild(this._rewardTipItem);
            this._attackBtn = ObjCreate.createGButton("", 470, loc1 - 8, 59, 32, this, "PetCpnAttackButton");
            this._attackBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAttackBtnClickHandler);
            this._attackBtn.drawNow();
            this._resultTxt = ObjCreate.createGTextField("", 470, loc1, 100, 20, this, GlobalStyle.textFormat6);
            this._resultTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(0, 35, 520, 2, this, ImagesConst.SplitLine);
            this._overSkin = ObjCreate.createBg(0, 5, 460, 30, null, ImagesConst.Friend_over);
            return;
        }

        /* internal  */onNameClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._petArenaInfo) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnView, this._petArenaInfo));
            }
            return;
        }

        /* internal  */getTipData(): string
        {
            var loc1=Language.getString(54671);
            if (this._petArenaInfo) 
            {
                if (this._isSystem) 
                {
                    loc1 = loc1 + Language.getString(54671);
                }
                else 
                {
                    loc1 = loc1 + ("\n" + PlayerUtil.getProxyAndNameByEntityIdAndName(this._petArenaInfo.entityId, "") + this._petArenaInfo.playerName);
                }
                loc1 = loc1 + Language.getStringByParam(54673, this._petArenaInfo.level, PetUtil.getPetTypeNameByCareer(this._petArenaInfo.career), PetColor.getColorTalent(this._petArenaInfo.talent), PetUtil.getColorGrowth(this._petArenaInfo.growth), PetUtil.getColorSpirit(this._petArenaInfo.spirit));
            }
            return "<textFormat leading=\'5\'><font color=\'#f0ea3f\'>" + loc1 + "</font></textFormat>";
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.Event */): void
        {
            addChildAt(this._overSkin, 0);
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.Event */): void
        {
            if (this._overSkin.parent) 
            {
                removeChild(this._overSkin);
            }
            return;
        }

        /* internal  */showRewardBitmap(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (!this._rewardBitmap) 
                {
                    this._rewardBitmap = ObjCreate.createBg(360, 8, 100, 20, null, ImagesConst.SelectedBg);
                }
                if (!this.contains(this._rewardBitmap)) 
                {
                    this.addChildAt(this._rewardBitmap, 0);
                }
            }
            else if (this._rewardBitmap && this.contains(this._rewardBitmap)) 
            {
                this.removeChild(this._rewardBitmap);
            }
            return;
        }

        /* internal  */onAttackBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=false;
            if (this._petArenaInfo) 
            {
                loc2 = Cache.instance.petCompetition.attckPetUid;
                if (loc4 = Cache.instance.petCompetition.petArenaEx) 
                {
                    loc3 = loc4.petInfo.uid;
                }
                loc5 = !(loc2 == loc3);
                if (loc2) 
                {
                    loc1 = loc2;
                }
                else 
                {
                    loc1 = loc3;
                }
                if (loc1 && !(loc1 == "")) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnAttack, {"petArenaInfo": _petArenaInfo, "uid": loc1, "isChangePet": loc5, "challengeType": _attackType}));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54669));
                }
            }
            return;
        }

        /* internal */ /* var */_avatarBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_avatar: GImageBitmap;

        /* internal */ /* var */_rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_growthTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_spiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_talentTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_typeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_rewardTxt: GTextFiled;

        /* internal */ /* var */_attackBtn: GButton;

        /* internal */ /* var */_rewardTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardTipItem: BlankTipItem;

        /* internal */ /* var */_resultTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_overSkin: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_petCpnInfo: PetCpnInfo;

        /* internal */ /* var */_attackType: int;

        /* internal */ /* var */_petArenaInfo: SPetArenaInfo;

        /* internal */ /* var */_isSystem: Boolean;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_reward: SReward;
    }
